package internal

import (
	"fmt"
	"leaf/gate"
	"reflect"
	"server/pb/pb_go/proto"
)

func init() {
	handler(&proto.C2S_Login{}, handleLogin)
}

func handler(m interface{}, h interface{}) {
	skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
}

func handleLogin(args []interface{}) {
	// 收到的消息
	m := args[0].(*proto.C2S_Login)
	// 消息的发送者
	a := args[1].(gate.Agent)
	// 输出收到的消息的内容
	fmt.Println(m.Account)
	fmt.Println(m.Password)
	fmt.Println(a.LocalAddr())
	message := proto.S2C_Login{}
	userInfo := proto.UserInfo{}
	userInfo.Name = "yorick"
	message.User = &userInfo
	a.WriteMsg(&message)
}
